package com.moyu.crowdsource.social.qq.config;

import com.moyu.crowdsource.autoconfigure.social.SocialAutoConfigurerAdapter;
import com.moyu.crowdsource.social.qq.connect.QQConnectionFactory;
import com.moyu.crowdsource.websetting.properties.QQProperties;
import com.moyu.crowdsource.websetting.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;

@Configuration
@ConditionalOnProperty(prefix = "moyu.security.social.qq", name = "app-id")
@EnableConfigurationProperties(SecurityProperties.class)
public class QQAutoConfig extends SocialAutoConfigurerAdapter {

  @Autowired private SecurityProperties securityProperties;

  /*
   * (non-Javadoc)
   *
   * @see
   * org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter
   * #createConnectionFactory()
   */
  @Override
  protected ConnectionFactory<?> createConnectionFactory() {
    System.out.println("QQAutoConfig");
    QQProperties qqConfig = securityProperties.getMySocialProperties().getQq();
    return new QQConnectionFactory(
        qqConfig.getProviderId(), qqConfig.getAppId(), qqConfig.getAppSecret());
  }
}
